@extends('admin.layouts.master')
@section('content')
    <table class="mdui-table mdui-table-hoverable mdui-typo">
        <caption class="mdui-typo-title">微博详情</caption>
        <thead>
        <tr>
            <th>ID</th>
            <th>用户昵称</th>
            <th>微博内容</th>
            <th>发表时间</th>
            <th>前台可见</th>
        </tr>
        </thead>
        <tbody>
        @foreach($weibos as $weibo)
            <tr>
                <td>{{$weibo->id}}</td>
                <td>{{$weibo->nickname}}</td>
                <td>{{$weibo->content}}</td>
                <td>{{$weibo->created_at}}</td>
                <td>
                    <label class="mdui-switch">
                        <input type="checkbox" is_show="{{$weibo->is_show}}"
                               class="change" {{$weibo->is_show==1?'checked':''}}/>
                        <i class="mdui-switch-icon"></i>
                    </label>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>
    <table class="mdui-table mdui-table-hoverable mdui-typo mdui-m-t-1">
        <caption class="mdui-typo-title">微博评论</caption>
        <thead>
        <tr>
            <th>#</th>
            <th>评论内容</th>
            <th>用户</th>
            <th>发表时间</th>
            <th>前台可见</th>
        </tr>
        </thead>
        <tbody>
        @foreach($details as $detail)
        <tr>
            <td>{{$detail->id}}</td>
            <td>
                {{$detail->content}}
            </td>
            <td>{{$detail->nickname}}</td>
            <td>{{$detail->created_at}}</td>
            <td>
                <label class="mdui-switch">
                    <input type="checkbox" is_view="{{$detail->is_view}}"
                           class="change_view" {{$detail->is_view==1?'checked':''}}/>
                    <i class="mdui-switch-icon"></i>
                </label>
            </td>
        </tr>
        @endforeach
        </tbody>
    </table>
@endsection
@section('js')
    <script>
        $(".change").click(function () {
            //获取每次选择得到的id
            var weibo_id = $(this).parent().parent().parent().find('td').first().text();
//            console.log(weibo_id);
            //增加一个标识
            var is_show = $(this).attr('is_show');
            //指定选定的ID
            var mythis = $(this);
            $.ajax({
                url: '/admin/weibo/'+ weibo_id +'/update',
                dataType: 'json',
                type:'get',
                data: {'is_show': is_show},
                success: function (data) {
                    if (data.message === 1) {
                        mythis.attr('checked', '');
                        mythis.attr('is_show', '1');
                    } else {
                        mythis.removeAttr('checked');
                        mythis.attr('is_show', '0');
                    }
                }
            });
        });
    </script>
    <script>
        $(".change_view").click(function () {
            //获取每次选择得到的id
            var detail_id = $(this).parent().parent().parent().find('td').first().text();
//            console.log(weibo_id);
            //增加一个标识
            var is_view = $(this).attr('is_view');
            //指定选定的ID
            var mythis = $(this);
            $.ajax({
                url: '/admin/weibo/'+ detail_id +'/status',
                dataType: 'json',
                type:'get',
                data: {'is_view': is_view},
                success: function (data) {
                    if (data.message === 1) {
                        mythis.attr('checked', '');
                        mythis.attr('is_view', '1');
                    } else {
                        mythis.removeAttr('checked');
                        mythis.attr('is_view', '0');
                    }
                }
            });
        });
    </script>
@endsection